package com.springcloud.test.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

/**
 * @Desc TODO
 * ----------------
 * @CLASS_NAME: DcController
 * ----------------
 * @Author jovi
 * ----------------
 * @Date 2020-03-24 15:41
 */
@RestController
public class DcController {

    @Resource
    private RestTemplate restTemplate;

    @GetMapping("/consumer")
    public String dc() {
        String url = "http://app-server/dc";
        System.out.println(url);

        // * Spring Cloud Ribbon有一个拦截器，它能够在这里进行实际调用的时候，自动的去选取服务实例，
        // * 并将实际要请求的IP地址和端口替换这里的服务名，从而完成服务接口的调用
        return restTemplate.getForObject(url, String.class);
    }
}
